# Maintainer (MSYS2): Michael Hansen <zrax0111@gmail.com>
# Contributor: Zach Bacon <zachbacon@vba-m.com>

_variant=-${KF5_VARIANT:-shared}
source "$(dirname ${BASH_SOURCE[0]})"/../mingw-w64-PKGBUILD-common/kde-frameworks5
_kde_f5_init_package "${_variant}" "kio"
pkgver=5.116.0
pkgrel=1
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: kio5'
)
pkgdesc="Resource and network access abstraction (mingw-w64)"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-extra-cmake-modules>=${pkgver}"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             $([[ "${MSYSTEM}" == "CLANGARM64" ]] || echo "${MINGW_PACKAGE_PREFIX}-kdoctools-qt5${_namesuff}>=${pkgver}"))
depends=()
if [ "${_variant}" = "-static" ]; then
  _kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-qt5${_namesuff}"
else
  makedepends+=("${MINGW_PACKAGE_PREFIX}-qt5-tools")
  depends+=("${MINGW_PACKAGE_PREFIX}-qt5-base")
fi
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-solid-qt5${_namesuff}>=${pkgver}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-kjobwidgets-qt5${_namesuff}>=${pkgver}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-kbookmarks-qt5${_namesuff}>=${pkgver}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-kwallet-qt5${_namesuff}>=${pkgver}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-libxslt"
optdepends=("${MINGW_PACKAGE_PREFIX}-kdoctools-qt5${_namesuff}>=${pkgver}: for the help kioslave")
groups=("${MINGW_PACKAGE_PREFIX}-kf5")
source=("https://download.kde.org/stable/frameworks/${pkgver%.*}/${_basename}-${pkgver}.tar.xz"{,.sig}
        "001-disable-gssapi-mingw.patch"
        "002-kio-qt5-workaround-kf6-conflict.patch")
sha256sums=('efb719d6659c39a03b165dca3b6c84f729a833290fc44e7e1f99625690b6115a'
            'SKIP'
            '2d455784452276f6894d1f323670184920d97e9fea2a0a5c13b4ff6dd9accceb'
            '43f606947b2aff3e3bcb6e7fe56dd72dc3a6513ef1c88c589936be7ce2bfbedf')
validpgpkeys=('53E6B47B45CEA3E0D5B7457758D0EE648A48B3BB') # David Faure <faure@kde.org>

prepare() {
  cd ${_basename}-${pkgver}
  # Resolving conflict with MSYS heimdal package.
  # Some day we need to create heimdal for mingw-w64
  patch -p1 -i "${srcdir}"/001-disable-gssapi-mingw.patch
  patch -p1 -i "${srcdir}"/002-kio-qt5-workaround-kf6-conflict.patch
  mkdir -p "${srcdir}"/build-${MSYSTEM}${_variant}
}

build() {
  local -a extra_config
  cd build-${MSYSTEM}${_variant}
  if [ "${_variant}" = "-static" ]; then
    extra_config+=( -DBUILD_SHARED_LIBS=NO )
  fi

  _kde_f5_build_env
  ${MINGW_PREFIX}/bin/cmake.exe ../${_basename}-${pkgver} \
    -DCMAKE_BUILD_TYPE=$(_kde_f5_CMAKE_BUILD_TYPE) \
    "${_kde_f5_KDE_INSTALL_DIRS[@]}" \
    -DBUILD_QCH=OFF \
    -DBUILD_TESTING=OFF \
    -DECM_DIR=${MINGW_PREFIX}/share/ECM \
    -DKF6_COMPAT_BUILD=ON \
    "${extra_config[@]}" \
    -G'Ninja'
  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd build-${MSYSTEM}${_variant}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install ./
}
